<?php

namespace App\Department\Controllers;

use App\Http\Controllers\Controller;
use App\Repositories\BaseApplyRepository;
use App\Services\BaseApplyService;
use App\Traits\BaseApplyTrait;
use Encore\Admin\Layout\Content;


abstract class BaseApplyController extends Controller
{
    use BaseApplyTrait;

    protected $title;
    protected $description = ['default' => '申请前登记', 'review' => '待审批', 'grant' => '已授权'];
    public $repository;
    protected $service;
    protected $role_type = 2;

    public function __construct(BaseApplyRepository $repository, BaseApplyService $service)
    {
        $this->repository = $repository;
        $this->service = $service;
    }

    protected function grid($action)
    {
        $grid = $this->repository->deptGrid();
        if ($action == 'grant') {
            $this->service->gridPublishColumns($grid, $this->role_type);
        } else {
            $this->service->gridColumns($grid, $this->role_type);
        }
        if ($action == 'review') {
            $grid->model()->where('dept_review_status', 0);
        }
        $grid->disableCreateButton();
        return $grid;
    }

    protected function form()
    {
        $form = $this->repository->form();
        $this->repository->formPublic($form, $this->role_type);
        $this->service->formFields($form, $this->role_type);
        return $form;
    }
}
